package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Accident;
import cn.wolfcode.crm.domain.Loss;
import cn.wolfcode.crm.page.PageResult;
import cn.wolfcode.crm.query.AccidentQueryObject;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IAccidentService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PermissionName;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("accident")
public class AccidentController {

    @Autowired
    private IAccidentService accidentService;

    @RequestMapping("")
    @RequiresPermissions("accident:index")
    @PermissionName("事故明细列表")
    public String index() {
        //只负责跳转到accident.jsp页面即可
        return "accident";
    }
    @RequestMapping("list")
    @RequiresPermissions("accident:list")
    @PermissionName("事故明细数据")
    @ResponseBody
    public PageResult list(AccidentQueryObject qo) {
        PageResult result=accidentService.query(qo);
        return result;
    }

    @RequestMapping("handlerAccident")
    @RequiresPermissions("accident:handlerAccident")
    @PermissionName("处理事故明细")
    @ResponseBody
    public JsonResult handlerAccident(Long id,Long stateId) {
        JsonResult result = new JsonResult();
        try {
            accidentService.handlerAccident(id,stateId);
        } catch (Exception e) {
            e.printStackTrace();
            result.mark("保存失败!!!");
        }
        return result;
    }
    @RequestMapping("save")
    @RequiresPermissions("accident:save")
    @PermissionName("事故明细更新")
    @ResponseBody
    public JsonResult save(Accident accident) {
        JsonResult result = new JsonResult();
        try {
            accidentService.save(accident);
        } catch (Exception e) {
            e.printStackTrace();
            result.mark("保存失败!!!");
        }
        return result;
    }
    @RequestMapping("getLossInfo")
    @ResponseBody
    public Loss getLossInfo(Long accidentId) {

        return accidentService.getLossInfo(accidentId);
    }
    @RequestMapping("saveAccidentLoss")
    @ResponseBody
    public JsonResult saveAccidentLoss(Loss loss,Long accidentId) {
        JsonResult result = new JsonResult();
        try {
            accidentService.saveAccidentLoss(loss,accidentId);
        } catch (Exception e) {
            e.printStackTrace();
            result.mark("保存失败");
        }
        return result;
    }



}